﻿using customshapeform;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace CSharpGDIDraw.Customshapeform
{
    public partial class Mr : Form
    {

        public Mr()
        {
            InitializeComponent();
            this.FormBorderStyle = FormBorderStyle.None;
            System.Drawing.Region myregion = BitmapToRegion.getRegionFast
                (new Bitmap(global::THenu.CSharpGDIDraw.Properties.Resources.Mrs_DD_BG) 
                , Color.Red, 50);
            RectangleF rt = myregion.GetBounds(this.CreateGraphics());
            this.Width = (int)rt.Width;
            this.Height = (int)rt.Height;
            this.Region = myregion;

            // 获取所有静态公共属性 

            list.Add(Brushes.LightPink);
            list.Add(Brushes.LightSkyBlue);
            list.Add(Brushes.YellowGreen);
            list.Add(Brushes.Orange);
            list.Add(Brushes.MediumAquamarine);
            list.Add(Brushes.MediumBlue);
            list.Add(Brushes.PaleVioletRed);
            list.Add(Brushes.HotPink);
            list.Add(Brushes.Magenta);
            list.Add(Brushes.SpringGreen);
            list.Add(Brushes.CornflowerBlue);
            list.Add(Brushes.DarkRed);
            list.Add(Brushes.DarkOrange);
            list.Add(Brushes.DeepPink);
            list.Add(Brushes.DarkSeaGreen);
            list.Add(Brushes.LightSteelBlue);
            //list.Add(new HatchBrush(HatchStyle.Divot, Color.Tomato, Color.WhiteSmoke));
            //list.Add(new HatchBrush(HatchStyle.ForwardDiagonal, Color.SlateBlue, Color.WhiteSmoke));
            //list.Add(new HatchBrush(HatchStyle.DarkVertical, Color.Purple, Color.WhiteSmoke));
            //list.Add(new HatchBrush(HatchStyle.DarkHorizontal, Color.Orchid, Color.WhiteSmoke));
            //list.Add(new HatchBrush(HatchStyle.DarkVertical, Color.DeepPink, Color.WhiteSmoke));
            //list.Add(new HatchBrush(HatchStyle.DarkVertical, Color.OliveDrab, Color.WhiteSmoke));
            //list.Add(new HatchBrush(HatchStyle.DarkHorizontal, Color.OrangeRed, Color.WhiteSmoke));
            //list.Add(new HatchBrush(HatchStyle.Divot, Color.PaleGoldenrod, Color.SlateBlue));
            list.Add(new HatchBrush(HatchStyle.ForwardDiagonal, Color.PaleGoldenrod, Color.Tomato));
            list.Add(new HatchBrush(HatchStyle.DottedDiamond, Color.PaleGoldenrod, Color.Purple));
            list.Add(new HatchBrush(HatchStyle.DarkHorizontal, Color.PaleGoldenrod, Color.Orchid));
            list.Add(new HatchBrush(HatchStyle.LargeCheckerBoard, Color.PaleGoldenrod, Color.DeepPink));
            list.Add(new HatchBrush(HatchStyle.DarkVertical, Color.PaleGoldenrod, Color.OliveDrab));
            list.Add(new HatchBrush(HatchStyle.LargeConfetti, Color.PaleGoldenrod, Color.OrangeRed));



        }
        private void Mr_Load(object sender, EventArgs e)
        {
            // 调用示例 == 在Load事件中调用使窗体逐渐显示
            //AnimateWindow(this.Handle, 2000, AW_BLEND | AW_ACTIVATE);
        }
        #region 初始化窗体边框阴影效果

        const int CS_DropSHADOW = 0x20000;
        const int GCL_STYLE = (-26);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int GetClassLong(IntPtr hwnd, int nIndex);
        #endregion


        #region 窗体拖动代码
        /// <summary>
        /// 窗体逐渐显示动画
        /// </summary>
        /// <param name="hWnd"></param>
        /// <param name="dwTime"></param>
        /// <param name="dwFlags"></param>
        /// <returns></returns>
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        protected static extern bool AnimateWindow(IntPtr hWnd, int dwTime, int dwFlags);
        public const Int32 AW_BLEND = 0x00080000;
        public const Int32 AW_CENTER = 0x00000010;
        public const Int32 AW_ACTIVATE = 0x00020000;
        public const Int32 AW_HIDE = 0x00010000;
        public const Int32 AW_SLIDE = 0x00040000;
        public const int WM_NCLBUTTONDOWN = 0xA1;
        public const int HTCAPTION = 0x2;
        /// <summary>
        /// 发送窗体消息
        /// </summary>
        /// <param name="hWnd"></param>
        /// <param name="Msg"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        [DllImportAttribute("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        /// <summary>
        /// 标记系统窗体开始移动
        /// </summary>
        /// <returns></returns>
        [DllImportAttribute("user32.dll")]
        public static extern bool ReleaseCapture();
        /// <summary>
        /// 窗体拖动代码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Mr_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);

            hasTip = false;
            this.toolTip1.Hide(this);

        }
        #endregion

        #region 随机彩色字符串
        List<Brush> list = new List<Brush>();
        string Content = "喜洋洋、美洋洋  冰 ❤ 冰 新年快乐";

        bool hasTip = true;
        private void timerAnimal_Tick(object sender, EventArgs e)
        {
            Random rd = new Random();
            DrawString(rd.Next(list.Count));
            if (hasTip)
            {

                this.toolTip1.Show("拖动我试试看,我可以消灭雪花哟", this, new Point(300, 400));
            }
        }

        public void DrawString(int index)
        {
            Graphics gh = this.CreateGraphics();

            gh.DrawString(Content,
            new Font("华文新魏", 18, FontStyle.Bold), list[index], new PointF(90, 510));
        }
        #endregion

        private void toolTip1_Popup(object sender, PopupEventArgs e)
        {
            hasTip = false;
        }
        private void Mr_KeyUp(object sender, KeyEventArgs e)
        {
           if( e.KeyCode == Keys.Escape)
           {
               this.Close();
           }
        }
    }

}
